package com.example.dllo.my36kr.share;

import android.content.Intent;
import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;

import com.example.dllo.my36kr.R;
import com.example.dllo.my36kr.search.SearchActivity;
import com.example.dllo.my36kr.share.all.AllFragment;
import com.example.dllo.my36kr.share.finish.FinishFragment;
import com.example.dllo.my36kr.share.fundraising.FundraisingFragment;
import com.example.dllo.my36kr.share.success.SuccessFragment;
import com.example.dllo.my36kr.tools.BaseFragment;

import java.util.ArrayList;

/**
 * Created by dllo on 16/8/15.
 */
public class ShareFragment extends BaseFragment {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private ShareAdapter adapter;
    private Button liwuBnt;
    private ImageView imageView;

    @Override
    protected int setLayout() {
        return R.layout.fragment_share;
    }

    @Override
    protected void initView() {
        tabLayout = bindView(R.id.tl_share);
        viewPager = bindView(R.id.vp_share);
        adapter = new ShareAdapter(getFragmentManager());
        liwuBnt = bindView(R.id.bnt_share_liwu);
        imageView = bindView(R.id.iv_tupian);
        liwuBnt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView.setVisibility(View.VISIBLE);
                RotateAnimation rAnime = new RotateAnimation(-45, 45, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                rAnime.setDuration(100);
                rAnime.setRepeatCount(4);
                rAnime.setRepeatMode(Animation.REVERSE);
                liwuBnt.startAnimation(rAnime);
            }
        });
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView.setVisibility(View.GONE);
            }
        });
        Button searchBnt = bindView(R.id.bnt_share_sousuo);
        searchBnt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), SearchActivity.class));
            }
        });

    }

    @Override
    protected void initData() {
        imageView.setVisibility(View.GONE);
        ArrayList<Fragment>fragments= new ArrayList<>();
        fragments.add(new AllFragment());
        fragments.add(new FundraisingFragment());
        fragments.add(new FinishFragment());
        fragments.add(new SuccessFragment());
        adapter.setFragments(fragments);
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.setTabTextColors(Color.rgb(0x98, 0x9d, 0xa8), Color.rgb(0x6c, 0x8f, 0xff));
        tabLayout.setSelectedTabIndicatorColor(Color.rgb(0x6c, 0x8f, 0xff));

    }
}
